﻿using Holdem.Interfaces;
using Holdem.Interfaces.Configuration;
using Holdem.Interfaces.Security;
using Holdem.Interfaces.Service;
using Holdem.Service;
using Holdem.ViewModel;


namespace TexasHoldemCalculator.View
{
	public partial class StartingHandsSelectionView
	{
        public ISkyDriveSecurityProvider SecurityProvider
        {
            get
            {
                return Factory.Instance.GetInstance<ISkyDriveSecurityProvider>();
            }
        }

        //public ISecurityOptionsProvider SecurityOptionsProvider
        //{
        //    get
        //    {
        //        return FactoryContainer.Instance.GetInstance<ISecurityOptionsProvider>();
        //    }
        //}

        //public IEncryptionProvider EncryptionProvider
        //{
        //    get
        //    {
        //        return FactoryContainer.Instance.GetInstance<IEncryptionProvider>();
        //    }
        //}

	    private HoldemStartingHandsViewModel HandContext
	    {
	        get { return DataContext as HoldemStartingHandsViewModel; }
	    }

	    public ITrialProvider TrialProvider
	    {
	        get
	        {
                return Factory.Instance.GetInstance<ITrialProvider>();
	        }
	    }

		public IHoldemPhoneConfiguration PersistentConfig
		{
			get
			{
                return Factory.Instance.GetInstance<IConfigurationService>().PersistentConfiguration;
			}
		}

        public IHoldemPhoneConfiguration TransientConfig
		{
			get
			{
                return Factory.Instance.GetInstance<IConfigurationService>().TransientConfiguration;
			}
		}

        private IAdProvider AdProvider
        {
            get
            {
                return Factory.Instance.GetInstance<IAdProvider>();
            }
        }

		public StartingHandsSelectionView()
		{
		    InitializeComponent();

		    SetAdInformation();

            this.SkyDriveSignInButton.SessionChanged += SecurityProvider.SkyDriveSignInButtonSessionChanged;

		    if( TrialProvider.IsTrial )
		        return;

		    if( TransientConfig.ContainsKey(ConfigKey.HoldemStartingHandsSelectionEventRegistration) )
		        return;

		    TransientConfig[ConfigKey.HoldemStartingHandsSelectionEventRegistration] = true;
		}

        private void SetAdInformation()
        {
            this.THCStartingHandsAd.AdUnitId = AdProvider.AdUnitId;
            this.THCStartingHandsAd.ApplicationId = AdProvider.ApplicationId;
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (!HandContext.IsCustomHandVisible)
                return;

            HandContext.UpdateStartingHandsSelectionVisibility();

            e.Cancel = true;
        }
	}
}